/**
This file is part of dbdjasperreport.

Copyright (C) 2008 Kue Vang aka Kou
Licensed under the Eclipse Public License, Version 1.0; 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at http://www.eclipse.org/legal/epl-v10.html 
Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and limitations 
under the License.
**/

import groovy.xml.MarkupBuilder
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.math.BigDecimal

class ReportModuleController{
	def operatorService = new OperatorService()
	def validationService = new ValidationService()
	def sessionExpireMsg = "Your Report selection has expired. Please re-select a 'System'."
	def messageDate1="Date must be in 'MM/DD/YYYY' format"
	def messageDate2=" is not a valid date"
	def index = { redirect(action:list,params:params) }
	def allowedMethods = [delete:'POST', save:'POST', update:'POST']
	
	def hidden = "hidden"
	def visible = "visible"
	def radioChecked = "true"
	def radioUnchecked = "false"
	DateFormat df = new SimpleDateFormat("MM/dd/yyyy")
	def codeListService //= new CodeListService()
	def whereClauseService
	//display value on list move buttons
	def addOne = ">"
	def minusOne  ="<"
	def addAll = ">>"
	def minusAll="<<"
	javax.sql.DataSource dataSource
	def list = {	
		session.systemId=null
		if(!params.max) 
		   params.max = 20   		
		
		def reportSystemList = ReportSystem.withCriteria{
			eq('systemEnded','N')
		}
		
		
		[ reportSystemList: reportSystemList]
	}
			
	def systemChange={
	    def reportList = []
		//println "systemId ====== "+params.systemId
		if(params.systemId){
		    session.systemId = params.systemId
			session.reportId =null
			session.parameterId = null
			session.operatorId = null
			reportList = Report.withCriteria{
				eq('reportSystem.id',new Integer(session.systemId))
				eq('reportEnded','N')
				//eq('showReport','Y')
			}
			def paramMap = [:]
			session.paramMap = paramMap
		}
		render g.reportList(value:reportList)
	}	
		
	def reportChange = {
	    def parameters=[]
		if(session.systemId){
			if(params.reportId ){
				session.reportId = params.reportId
			
				//reset session.parameterId and session.operatorId
				session.parameterId = null
				session.operatorId = null
				parameters = ReportParameter.withCriteria{
					eq('parameterFilterable','Y')
					eq('report.id',new Integer(session.reportId))
					eq('parameterEnded','N')
				}	
				loadParameterMap(parameters)			
			}
			render g.paramList(value:parameters)	
		}
		else
			render g.errorMsg(message:sessionExpireMsg)
	}
	
	def loadParameterMap={parameters->
		session.paramMap.clear()
			parameters.each{param ->
			   param.setIdOperatorSelected(param.defaultOperator)
				if(param.dataType.toString() == DataTypeService.codeDataType){//code data type
				    param.setCodeSourceList(codeListService.codeSourceList(param.id))
					param.setCodeSelectedList([])//set to an empty list
				}
				else if(param.dataType.toString() == DataTypeService.entityDataType){
					param.setIdOperatorSelected2(new Integer(OperatorService.strStartsWith))//set to starts with
					param.setCodeSourceList([])
					param.setCodeSelectedList([])//set to an empty list
				}
				session.paramMap.put(param.id,param)
			}
	}
	
	def paramFieldChange ={		
		session.parameterId=params.parameterId	
		renderDataEntryScreen()		
	}
	
	def renderDataEntryScreen={
		if(session.paramMap){			
			def rptParam = session.paramMap.get(new Integer(session.parameterId))
			session.operatorId = rptParam.idOperatorSelected
			String dataType = rptParam.dataType.toString()
			if(dataType == DataTypeService.dateDataType){//date				
				displayDateEntryScreen()
			}
			else if(dataType == DataTypeService.numDataType){//number
				displayNumberEntryScreen()
			}
			else if(dataType == DataTypeService.strDataType){//string
				displayStringEntryScreen()
			}
			else if(dataType == DataTypeService.codeDataType){//code
				displayCodeEntryScreen()
			}
			else if(dataType == DataTypeService.entityDataType){//entity
				displayEntityEntryScreen()
			}
			else if(dataType == DataTypeService.booleanDataType){//boolean
				displayBooleanEntryScreen()
			}
			else if(dataType == DataTypeService.yesNoDataType){//Yes/No
				displayYesNoEntryScreen()
			}
		}
		else
			render g.errorMsg(message:sessionExpireMsg)		
	}
	
	def hideReportList={
		render g.emptyReportList()
	}
	
	def hideParameterList={
		render g.emptyParamList()
	}
	
	def hideEntry={
	    render g.hiddenField(name:"hide1",value:"nothing")
	}
	
	/** 
	* DATE   - EVENT methods 
	*/
	def dateOperatorChange = {				
		if(params.operatorId && session.parameterId){
			session.operatorId = params.operatorId
			displayDateEntryScreen()
		}		
	}
	
	def displayDateEntryScreen={
	    if(session.operatorId && session.parameterId){
		    def rptParam = session.paramMap.get(new Integer(session.parameterId))
			rptParam.setIdOperatorSelected(new Integer(session.operatorId))
			
			//boolean var for showing date Entry divs
			def showDateDiv4 = hidden
			def showDateDiv5 = hidden
			def showDateDiv6 = hidden
			def showDateDiv7 = hidden
			def showDateDiv8 = hidden
			def showDateDiv9 = hidden
			String 	dateBetween1Str=""
			String	dateBetween2Str=""
			String	dateGreaterEqualStr=""
			String	dateLessEqualStr=""
			String	dateEqualStr=""
		
		    String operatorId = rptParam.idOperatorSelected.toString()
			if(operatorId== OperatorService.dateBetween){
				showDateDiv4 = visible	
				if(rptParam.dateBetween1)
				    dateBetween1Str = df.format(rptParam.dateBetween1)
				if(rptParam.dateBetween2)
					dateBetween2Str = df.format(rptParam.dateBetween2)
			}
			else if(operatorId==OperatorService.dateGreaterEqual){
				showDateDiv5=visible
				if(rptParam.dateGreaterEqual)
					dateGreaterEqualStr = df.format(rptParam.dateGreaterEqual)
			}
			else if(operatorId==OperatorService.dateLessEqual){
				showDateDiv6=visible
				if(rptParam.dateLessEqual)
					dateLessEqualStr = df.format(rptParam.dateLessEqual)
			}
			else if(operatorId==OperatorService.dateEqual){
				showDateDiv7=visible
				if(rptParam.dateEqual)
					dateEqualStr = df.format(rptParam.dateEqual)
			}
			else if(operatorId==OperatorService.datePastDays)
				showDateDiv8=visible
			else if(operatorId==OperatorService.datePastMonths)
				showDateDiv9=visible
						
			render g.dateEntryScreen(rptParam:rptParam,	showDateDiv4:showDateDiv4, showDateDiv5:showDateDiv5, 
										showDateDiv6:showDateDiv6, showDateDiv7:showDateDiv7,
										showDateDiv8:showDateDiv8, showDateDiv9:showDateDiv9,
										dateBetween1Str:dateBetween1Str, dateBetween2Str:dateBetween2Str,
										dateGreaterEqualStr:dateGreaterEqualStr, dateLessEqualStr:dateLessEqualStr,
										dateEqualStr:dateEqualStr)				
		}
	}
	
	def renderDateMsg1={msg->
		render g.errorMsg(message:msg)
	}
		
	def renderDateMsg2={str->
		render g.errorMsg(message:"'"+str+"'"+messageDate2)
	}
	
	def saveDateBetween1={
		if(!validationService.validDateFormat(params.dateBetween1Str)){
			renderDateMsg1(messageDate1)
		}
		else{
			if(validationService.validDate(params.dateBetween1Str)){
				def param = session.paramMap.get(new Integer(session.parameterId))
				if(params.dateBetween1Str){
					String strDate = params.dateBetween1Str
					Date date = df.parse(strDate)
					param.setDateBetween1(date)
				}
				else
					param.setDateBetween1(null)
				renderDateMsg1("")
			}
			else
				renderDateMsg2(params.dateBetween1Str)
		}
	}
	
	def saveDateBetween2={
		if(!validationService.validDateFormat(params.dateBetween2Str))
			renderDateMsg1(messageDate1)
		else{
			if(validationService.validDate(params.dateBetween2Str)){
				def param = session.paramMap.get(new Integer(session.parameterId))
				if(params.dateBetween2Str){
					String strDate = params.dateBetween2Str
					Date date = df.parse(strDate)
					param.setDateBetween2(date)
				}
				else
					param.setDateBetween2(null)
				renderDateMsg1("")
			}
			else
				renderDateMsg2(params.dateBetween2Str)
		}
	}
	
	def saveDateGreaterEqual={
		if(!validationService.validDateFormat(params.dateGreaterEqualStr))
			renderDateMsg1(messageDate1)
		else{
			if(validationService.validDate(params.dateGreaterEqualStr)){
				def param = session.paramMap.get(new Integer(session.parameterId))
				if(params.dateGreaterEqualStr){
					String strDate = params.dateGreaterEqualStr
					Date date = df.parse(strDate)
					param.setDateGreaterEqual(date)
				}
				else
					param.setDateGreaterEqual(null)
				renderDateMsg1("")
			}
			else
				renderDateMsg2(params.dateGreaterEqualStr)
		}
	}
	
	def saveDateLessEqual={
		if(!validationService.validDateFormat(params.dateLessEqualStr))
			renderDateMsg1(messageDate1)
		else{
			if(validationService.validDate(params.dateLessEqualStr)){
				def param = session.paramMap.get(new Integer(session.parameterId))
				if(params.dateLessEqualStr){
					String strDate = params.dateLessEqualStr
					Date date = df.parse(strDate)
					param.setDateLessEqual(date)
				}
				else
					param.setDateLessEqual(null)
				renderDateMsg1("")
			}
			else
				renderDateMsg2(params.dateLessEqualStr)
		}		
	}
	
	def saveDateEqual={
		if(!validationService.validDateFormat(params.dateEqualStr))
			renderDateMsg1(messageDate1)
		else{
			if(validationService.validDate(params.dateEqualStr)){			
				def param = session.paramMap.get(new Integer(session.parameterId))			
				if(params.dateEqualStr){
					String strDate = params.dateEqualStr
					Date date = df.parse(strDate)
					param.setDateEqual(date)
				}
				else
					param.setDateEqualStr(null)
				renderDateMsg1("")
			}
			else
				renderDateMsg2(params.dateEqual)
		}
	}
	
	def saveDatePastDay={
		if(validationService.isNumeric(params.datePastDay)){
			def param = session.paramMap.get(new Integer(session.parameterId))	
			if(params.datePastDay)
				param.setDatePastDay(new Integer(params.datePastDay))
			else
				param.setDatePastDay(null)
			render g.errorMsg(message:"")
		}		
		else
			renderNumErrorMsg(params.datePastDay)
	}	
	
	def saveDatePastMonth={		
		if(validationService.isNumeric(params.datePastMonth)){
			def param = session.paramMap.get(new Integer(session.parameterId))	
			if(params.datePastMonth)
				param.setDatePastMonth(new Integer(params.datePastMonth))
			else
				param.setDatePastMonth(null)	
			render g.errorMsg(message:"")
		}		
		else
			renderNumErrorMsg(params.datePastMonth)
	}
	
	/**
	*  NUMBER  -  EVENT methods
	**/
	def numberOperatorChange={
		if(params.operatorId && session.parameterId){
			session.operatorId = params.operatorId			
			displayNumberEntryScreen()
		}	
	}
	
	def displayNumberEntryScreen={
		if(session.operatorId && session.parameterId){
			def rptParam = session.paramMap.get(new Integer(session.parameterId))
			rptParam.setIdOperatorSelected(new Integer(session.operatorId))
			def showNumDiv1 = hidden
			def showNumDiv2 = hidden
			def showNumDiv3 = hidden
			def showNumDiv4 = hidden
			def showNumDiv5 = hidden
			String operatorId = rptParam.idOperatorSelected.toString()
			if(operatorId == OperatorService.numEqual)
				showNumDiv1 = visible
			else if(operatorId == OperatorService.numGreaterEqual)
				showNumDiv2 = visible
			else if(operatorId == OperatorService.numLessEqual)
				showNumDiv3 = visible
			else if(operatorId == OperatorService.numBetween)
				showNumDiv4 = visible
			else if(operatorId == OperatorService.numNotEqual)
				showNumDiv5 = visible
				
			render g.numberEntryScreen(rptParam:rptParam, showNumDiv5:showNumDiv5,
										showNumDiv1:showNumDiv1, showNumDiv2:showNumDiv2,
										showNumDiv3:showNumDiv3, showNumDiv4:showNumDiv4)
		}
	}
	
	def renderNumErrorMsg={str->
		render g.errorMsg(message:"'"+str+"' must be numeric")
	}
	
	def saveNumEqual={
		if(validationService.isNumeric(params.numEqual)){
			def param = session.paramMap.get(new Integer(session.parameterId))
			if(params.numEqual)
				param.setNumEqual(new BigDecimal(params.numEqual))
			else
				param.setNumEqual(null)	
			render g.errorMsg(message:"")
		}		
		else
			renderNumErrorMsg(params.numEqual)
	}
	
	def saveNumGreaterEqual={
	    if(validationService.isNumeric(params.numGreaterEqual)){
			def param = session.paramMap.get(new Integer(session.parameterId))	
			if(params.numGreaterEqual)
				param.setNumGreaterEqual(new BigDecimal(params.numGreaterEqual))
			else
				param.setNumGreaterEqual(null)
			render g.errorMsg(message:"")
		}		
		else
			renderNumErrorMsg(params.numGreaterEqual)
	}
	
	def saveNumLessEqual={
		if(validationService.isNumeric(params.numLessEqual)){
			def param = session.paramMap.get(new Integer(session.parameterId))		
			if(params.numLessEqual)
				param.setNumLessEqual(new BigDecimal(params.numLessEqual))
			else
				param.setNumLessEqual(null)	
			render g.errorMsg(message:"")
		}		
		else
			renderNumErrorMsg(params.numLessEqual)
	}
	
	def saveNumBetween1={
	    if(validationService.isNumeric(params.numBetween1)){
			def param = session.paramMap.get(new Integer(session.parameterId))	
			if(params.numBetween1)
				param.setNumBetween1(new BigDecimal(params.numBetween1))
			else
				param.setNumBetween1(null)	
			render g.errorMsg(message:"")
		}		
		else
			renderNumErrorMsg(params.numBetween1)
	}
	
	def saveNumBetween2={
		if(validationService.isNumeric(params.numBetween2)){
			def param = session.paramMap.get(new Integer(session.parameterId))	
			if(params.numBetween2)
				param.setNumBetween2(new BigDecimal(params.numBetween2))
			else
				param.setNumBetween2(null)
			render g.errorMsg(message:"")
		}
		else
			renderNumErrorMsg(params.numBetween2)
	}
	
	def saveNumNotEqual={
		if(validationService.isNumeric(params.numNotEqual)){
			def param = session.paramMap.get(new Integer(session.parameterId))	
			if(params.numNotEqual)
				param.setNumNotEqual(new BigDecimal(params.numNotEqual))
			else
				param.setNumNotEqual(null)
			render g.errorMsg(message:"")
		}
		else
			renderNumErrorMsg(params.numNotEqual)
	}
	
	/**
	*   STRING Event  methods
	**/
	def stringOperatorChange={
		if(params.operatorId && session.parameterId){
			session.operatorId = params.operatorId			
			displayStringEntryScreen()
		}	
	}
	
	def displayStringEntryScreen={	
		if(session.operatorId && session.parameterId){
			def rptParam = session.paramMap.get(new Integer(session.parameterId))
			rptParam.setIdOperatorSelected(new Integer(session.operatorId))
			renderStringEntry(rptParam)
		}
	}
	
	def saveStringInput={
		if(params.strInput){
		def param = session.paramMap.get(new Integer(session.parameterId))				
		param.setStrInput(params.strInput)	
		}
	}
	
	def renderStringEntry={rptParam->
		render g.stringEntryScreen(rptParam:rptParam)
	}
	
	/**
	*   CODE Events methods
	**/
	def displayCodeEntryScreen={
	    def rptParam = session.paramMap.get(new Integer(session.parameterId))		
		renderCodeScreen(rptParam)
	}
	
	def renderCodeScreen={rptParam->
		def codeSelectedList = rptParam.codeSelectedList
		def codeSourceList = rptParam.codeSourceList
		
		Collections.sort(codeSourceList,new ListCompare())
		Collections.sort(codeSelectedList,new ListCompare())
		
		render g.codeEntryScreen(codeSourceList:codeSourceList,
								 codeSelectedList:codeSelectedList,
								 rptParam:rptParam, addOne:addOne, minusOne:minusOne,
								 addAll:addAll, minusAll:minusAll)
	}
	
	def codeAddOne={
	//println "params.codeSourceList == "+params.codeSourceList
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		def codeSelectedList = rptParam.codeSelectedList
		def codeSourceList = rptParam.codeSourceList
		int tokenCount;
		StringTokenizer st = new StringTokenizer(params.codeSourceList.toString(), ",")
		tokenCount = st.countTokens()
		if(params.codeSourceList){
			if(tokenCount == 1){
			    //when only one item is selected: Need special processing 
				String codeSelected = st.nextToken()
				for(int i=codeSourceList.size()-1;i>=0;i--){
					Code code2 = codeSourceList[i]
					if(code2.id.toString() == codeSelected){
						boolean codeExist = false
						for(int x=0;x<=codeSelectedList.size()-1;x++){
							Code code = codeSelectedList[x]
							if(code.id == code2.id){
								codeExist = true
								break;
							}
						}
						if(!codeExist)
							codeSelectedList << code2
						codeSourceList.remove(i)
						break
					}			
				}				
			}
			else{
				/**
				*	loop through all the user's selected values and find each value in the source list.
				*	When it's found and it's not already in the selected list add and delete it from the source list
				*	else if the value already exist in the selected list just delete it from the source list
				*/
				for(int y = params.codeSourceList.size()-1;y>=0;y--){
					def codeSelected = params.codeSourceList[y]
					for(int i=codeSourceList.size()-1;i>=0;i--){						
						Code code2 = codeSourceList[i]
						if(code2.id.toString() == codeSelected.toString()){							
							boolean codeExist = false
							for(int x=0;x<=codeSelectedList.size()-1;x++){
								Code code = codeSelectedList[x]
								if(code.id == code2.id){
									codeExist = true
									break;
								}
							}
							if(!codeExist)
								codeSelectedList << code2
							codeSourceList.remove(i)						
							break
						}
					}
				}	
			}	
			rptParam.setCodeSourceList(codeSourceList)
			rptParam.setCodeSelectedList(codeSelectedList)
		}
			
		if(rptParam.dataType.toString() == DataTypeService.codeDataType)
			renderCodeScreen(rptParam)
		else
			renderEntityScreen(rptParam)
	}
	
	def codeMinusOne={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		def codeSelectedList = rptParam.codeSelectedList
		def codeSourceList = rptParam.codeSourceList
		int tokenCount;
		StringTokenizer st = new StringTokenizer(params.codeSelectedList.toString(), ",")
		tokenCount = st.countTokens()
		
		if(params.codeSelectedList){
			if(tokenCount == 1){
			    //when only one item is selected: Need special processing for this
				String codeSelected = st.nextToken()
				for(int i=codeSelectedList.size()-1;i>=0;i--){
					Code code2 = codeSelectedList[i]
					if(code2.id.toString() == codeSelected){
						boolean codeExist = false
						for(int x=0;x<=codeSourceList.size()-1;x++){
							Code code = codeSourceList[x]
							if(code.id == code2.id){
								codeExist = true
								break;
							}
						}
						if(!codeExist)
							codeSourceList << code2
						codeSelectedList.remove(i)
						break
					}			
				}
				
			}
			else{
				for(int y = params.codeSelectedList.size()-1;y>=0;y--){
					def codeSelected = params.codeSelectedList[y]
					for(int i=codeSelectedList.size()-1;i>=0;i--){
						Code code2 = codeSelectedList[i]
						if(code2.id == codeSelected){
							boolean codeExist = false
							for(int x=0;x<=codeSourceList.size()-1;x++){
								Code code = codeSourceList[x]
								if(code.id == code2.id){
									codeExist = true
									break;
								}
							}
							if(!codeExist)
								codeSourceList << code2
							codeSelectedList.remove(i)
							break
						}
					}
				}	
			}
			rptParam.setCodeSourceList(codeSourceList)
			rptParam.setCodeSelectedList(codeSelectedList)
		}
	
		if(rptParam.dataType.toString()== DataTypeService.codeDataType)
			renderCodeScreen(rptParam)
		else
			renderEntityScreen(rptParam)
	}
	
	def codeAddAll={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		def codeSelectedList = rptParam.codeSelectedList
		def codeSourceList = rptParam.codeSourceList
		for(int i=codeSourceList.size()-1;i>=0;i--){
			Code code2 = codeSourceList[i]
			boolean codeExist = false
			for(int x=0;x<=codeSelectedList.size()-1;x++){
				Code code = codeSelectedList[x]
				if(code.id == code2.id){
					codeExist = true
					break;
				}
			}
			if(!codeExist)
				codeSelectedList << code2
			codeSourceList.remove(i)						
		}	
		rptParam.setCodeSourceList(codeSourceList)
		rptParam.setCodeSelectedList(codeSelectedList)
	
		if(rptParam.dataType.toString()== DataTypeService.codeDataType)//code data type			
			renderCodeScreen(rptParam)
		else
			renderEntityScreen(rptParam)
	}
	
	def codeMinusAll={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		def codeSelectedList = rptParam.codeSelectedList
		def codeSourceList = rptParam.codeSourceList
		for(int i=codeSelectedList.size()-1;i>=0;i--){
			Code code2 = codeSelectedList[i]
			boolean codeExist = false
			for(int x=0;x<=codeSourceList.size()-1;x++){
				Code code = codeSourceList[x]
					if(code.id == code2.id){
						codeExist = true
						break;
				}
			}
			if(!codeExist)
				codeSourceList << code2
			codeSelectedList.remove(i)				
		}	
		rptParam.setCodeSourceList(codeSourceList)
		rptParam.setCodeSelectedList(codeSelectedList)
			
		if(rptParam.dataType.toString()== DataTypeService.codeDataType)//code data type			
			renderCodeScreen(rptParam)
		else
			renderEntityScreen(rptParam)
	}
		
	/**
	*   Entity Events methods
	**/
	def displayEntityEntryScreen={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))	
		renderEntityScreen(rptParam)
	}
	
	def entityOperatorChange={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		session.operatorId = params.operatorId
		rptParam.setIdOperatorSelected2(new Integer(session.operatorId))
	}
	
	def saveEntitySearchStr={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		rptParam.setStrInput(params.strInput)
	}	
	
	def entitySearch={		
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		rptParam.setCodeSourceList(codeListService.entitySourceList(rptParam.id,rptParam.strInput, rptParam.idOperatorSelected2))
		renderEntityScreen(rptParam)
	}
	
	def entityClear={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		rptParam.setCodeSourceList([])
		renderEntityScreen(rptParam)
	}
	
	def entityReset={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		rptParam.setCodeSelectedList([])
		rptParam.setCodeSourceList([])
		renderEntityScreen(rptParam)
	}
	
	def renderEntityScreen={rptParam->
		def codeSourceList = rptParam.codeSourceList
		def codeSelectedList = rptParam.codeSelectedList
		Collections.sort(codeSourceList,new ListCompare())
		Collections.sort(codeSelectedList,new ListCompare())
		render g.entityEntryScreen(codeSourceList:codeSourceList,
								 codeSelectedList:codeSelectedList,
								 rptParam:rptParam, addOne:addOne, minusOne:minusOne,
								 addAll:addAll, minusAll:minusAll)
	}
	
	/**
	*   Boolean Events methods
	**/
	def booleanOptionChange={
		if(params.operatorId && session.parameterId){
			session.operatorId = params.operatorId	
			def param = session.paramMap.get(new Integer(session.parameterId))	
			param.setIdOperatorSelected(new Integer(session.operatorId))
		}	
	}
	
	def displayBooleanEntryScreen={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		rptParam.setIdOperatorSelected(new Integer(session.operatorId))
		renderBooleanScreen(rptParam)
	}
	
	def renderBooleanScreen={rptParam->
		render g.booleanEntryScreen(rptParam:rptParam)
	}
	
	def yesNoOptionChange={
		if(params.operatorId && session.parameterId){
			session.operatorId = params.operatorId	
			def param = session.paramMap.get(new Integer(session.parameterId))	
			param.setIdOperatorSelected(new Integer(session.operatorId))
		}
	}
	
	def displayYesNoEntryScreen={
		def rptParam = session.paramMap.get(new Integer(session.parameterId))
		rptParam.setIdOperatorSelected(new Integer(session.operatorId))
		renderYesNoScreen(rptParam)
	}
	
	def renderYesNoScreen={rptParam->
		render g.yesNoEntryScreen(rptParam:rptParam)
	}
	
	/**	
	*	Reset Parameter methods
	*/
	def resetAllParam={
	//println "reset param"
		if(session.paramMap && session.reportId && session.parameterId){		
			def parameters = ReportParameter.withCriteria{
				eq('parameterFilterable','Y')
				eq('report.id',new Integer(session.reportId))
				eq('parameterEnded','N')
			}
			loadParameterMap(parameters)
			renderDataEntryScreen()
		}
		else
			render g.errorMsg(message:"")
	}	
}